package ajax.quanxuan.sys.dao;

import ajax.quanxuan.sys.entity.Role;
import ajax.quanxuan.sys.entity.User;
import ajax.quanxuan.vo.DeptVo;
import ajax.quanxuan.vo.UserVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Set;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author KazuGin
 * @since 2024-07-03
 */
@Mapper

public interface UserMapper extends BaseMapper<User> {
    /**
     * 分页查询用户列表
     * @param page
     * @param userVo
     * @return
     * @throws Exception
     */

    IPage<User> findUserListByPage(@Param("page") IPage<User> page, @Param("user") UserVo userVo, @Param("dept")DeptVo deptVo)throws Exception;

    /**
     * 根据用户id查询改用户拥有的角色列表
      * @param id
     * @return
     */
    @Select("SELECT rid FROM sys_role_user where uid=#{uid}")
    Set<Integer> findUserRoleByUserId(int id);

    /**
     * 根据用户编号删除用户角色的数据
     * @param userId
     * @throws Exception
     */
    @Delete("delete from sys_role_user where uid=#{userid}")
    void deleteUserRoleByUserId(int userId) throws Exception;
    @Insert("INSERT INTO sys_role_user (rid,uid) values(#{rid},#{uid}) ")
    void insertUserRole(@Param("uid") int userId, @Param("rid") String rid) throws Exception;

}
